package com.ww.yaodao.controller;

import com.ww.yaodao.model.bo.TypesDO;
import com.ww.yaodao.model.vo.type.TypeRespVO;
import com.ww.yaodao.model.vo.type.TypeVO;
import com.ww.yaodao.service.TypeService;
import com.ww.yaodao.util.BaseResult;
import com.ww.yaodao.util.ResultEnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类别模块
 */
@RestController
@RequestMapping("type")
@Api(tags = "药品类别")
@Slf4j
public class TypeController {
    @Autowired
    private TypeService typeService;

    /**
     * 得到所有的药品类别
     *
     * @return
     */
    @GetMapping("getType")
    @ApiOperation("查询所有药品类别")
    public BaseResult<List<TypesDO>> getAllType() {
        List<TypesDO> list = typeService.getAllType();
        if (list == null) {
            return BaseResult.error(ResultEnums.SELECT_ERROR);
        }
        return BaseResult.success(list);
    }

    @GetMapping("{id}")
    @ApiOperation("删除药品分类")
    public TypeRespVO deleteById(@ApiParam("药品分类id") @PathVariable("id") Integer id){
        log.info("进入删除药品分类....");
        return  typeService.delete(id);
    }

    @PostMapping("/addType")
    @ApiOperation("添加类别")
    public TypeRespVO addType(@RequestBody TypeVO typeVO){
        log.info("进入添加类别...");
        return typeService.insertType(typeVO);
    }
}
